<template>
  <div id="app">
    <!-- 卡片组件 -->
    <el-card class='login-card'>
      <!-- 登录表单 -->
      <el-form style="margin-top: 50px" :model="loginForm" :rules="loginRules" ref="loginForm">
        <el-form-item prop="mobile">
          <el-input placeholder="请输入手机号" v-model="loginForm.mobile"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input placeholder="请输入密码" v-model="loginForm.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width: 100%" @click="submit">登录</el-button>
        </el-form-item>

      </el-form>
    </el-card>
  </div>
</template>

<script>

export default {
  name: 'App',
  data () {
    const fn = (rule, value, callback)=> {value.charAt(2)==='9'?callback():callback(new Error('第三位必须为9'))}
    return {
      loginForm: {
        mobile: '',
        password: ''
      },
      loginRules: {
        mobile: [{required:true,message:'手机号不能为空',trigger:'blur'},
        {pattern: /^1[3-9]\d{9}$/, message:'手机号格式错误',trigger:'blur'},
        {validator: fn, trigger:'blur'}
        ],
        password: [{required:true,message:'密码不能为空',trigger:'blur'},
        {min:6,max:16, message:'密码格式错误',trigger:'blur'}
        ]
      }
    }
  },
  methods: {
    submit () {
      this.$refs.loginForm.validate(function (v) {
        if (v) {
          console.log('校验通过');
        } else {
          console.log('校验失败，请重试');
        }
      })
    }
  },
  components: {

  }
}
</script>

<style scoped>
 #app {
   width: 100%;
   height: 100vh;
   background-color: pink;
   display: flex;
   justify-content: center;
   align-items: center;
 }
 .login-card {
   width: 440px;
   height: 300px;
 }
</style>
